package com.timesheet.gui.efforttracker.composite;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;

public class SectionUtilisationComposite extends Composite {

	private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
	private Section sectionSavedEffort;
	private UtilisationComposite newEffortResultTableComposite;

	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public SectionUtilisationComposite(Composite parent, int style) {
		super(parent, style);
		addDisposeListener(new DisposeListener() {

			public void widgetDisposed(DisposeEvent e) {
				toolkit.dispose();
			}
		});
		toolkit.adapt(this);
		toolkit.paintBordersFor(this);
		setLayout(new GridLayout(1, false));
		Section sctnNewEffort = toolkit.createSection(this, Section.TWISTIE | Section.TITLE_BAR);
		sctnNewEffort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		toolkit.paintBordersFor(sctnNewEffort);
		sctnNewEffort.setText("Search");
		sctnNewEffort.setExpanded(true);

		WSRDateChooseComposite createNewEffortComposite = new WSRDateChooseComposite(sctnNewEffort, SWT.NONE);
		toolkit.adapt(createNewEffortComposite);
		toolkit.paintBordersFor(createNewEffortComposite);
		sctnNewEffort.setClient(createNewEffortComposite);

		sectionSavedEffort = toolkit.createSection(this, Section.TWISTIE | Section.TITLE_BAR);
		sectionSavedEffort.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		toolkit.paintBordersFor(sectionSavedEffort);
		sectionSavedEffort.setText("Search Result");
		sectionSavedEffort.setExpanded(true);

		newEffortResultTableComposite = new UtilisationComposite(sectionSavedEffort, SWT.NONE);
		((GridData) newEffortResultTableComposite.getTable().getLayoutData()).heightHint = 103;
		((GridData) newEffortResultTableComposite.getTable().getLayoutData()).verticalAlignment = SWT.TOP;
		toolkit.adapt(newEffortResultTableComposite);
		toolkit.paintBordersFor(newEffortResultTableComposite);
		sectionSavedEffort.setClient(newEffortResultTableComposite);
		
		Section sctnEditNewEffort = toolkit.createSection(this, Section.TWISTIE | Section.TITLE_BAR);
		sctnEditNewEffort.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		toolkit.paintBordersFor(sctnEditNewEffort);
		sctnEditNewEffort.setText("Detailed Information");
		sctnEditNewEffort.setExpanded(true);
		
		DetailedUtilisationComposite editNewEffortComposite = new DetailedUtilisationComposite(sctnEditNewEffort, SWT.NONE);
		toolkit.adapt(editNewEffortComposite);
		toolkit.paintBordersFor(editNewEffortComposite);
		sctnEditNewEffort.setClient(editNewEffortComposite);

	}

}
